//
//  GGMatchesScheduleCell.swift
//  DongBaoDemo
//
//  Created by 陈志勇 on 2018/8/5.
//  Copyright © 2018年 陈志勇. All rights reserved.
//

import UIKit

class GGMatchesScheduleCell: UITableViewCell {
    
    @IBOutlet weak var roundLabel: UILabel!
    @IBOutlet weak var raceNameLabel: UILabel!
    @IBOutlet weak var raceStateLabel: UILabel!
    
    @IBOutlet weak var team1ImageView: UIImageView!
    @IBOutlet weak var tem1NameLabel: UILabel!
    @IBOutlet weak var team2ImageView: UIImageView!
    @IBOutlet weak var team2Label: UILabel!
    @IBOutlet weak var startTimeLabel: UILabel!
    @IBOutlet weak var vsLabel: UILabel!
    
    var schedule: Schedule? {
        didSet {
            guard let schedule = schedule else {
                return
            }
            
            roundLabel.text = "第" + schedule.round! + "轮"
            raceNameLabel.text = schedule.race_name
            if let status = schedule.status {
                switch status {
                case .enroll:
                    raceStateLabel.text = "未开始"
                case .race:
                    raceStateLabel.text = "\(schedule.consume_time!)'"
                    vsLabel.text = "\(schedule.team1_score!) - \(schedule.team2_score!)"
                    vsLabel.textColor = .green
                case .over:
                    raceStateLabel.text = "已结束"
                    vsLabel.text = "\(schedule.team1_score!) - \(schedule.team2_score!)"
                    vsLabel.textColor = .red
                }
            }
            let team1url = "http://football.dooksport.com" + schedule.team1_image!
            team1ImageView.kf.setImage(with: URL(string: team1url))
            let team2url = "http://football.dooksport.com" + schedule.team2_image!
            team2ImageView.kf.setImage(with: URL(string: team2url))
            
            tem1NameLabel.text = schedule.team1_shortname
            team2Label.text = schedule.team2_shortname
            
            if let startTime = schedule.start_time, let time = Double(startTime) {
                let date = Date(timeIntervalSince1970: time)
                let dateStr = date.toString(dateFormat: "yyyy-MM-dd HH:mm")
                startTimeLabel.text = dateStr
            }
        }
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}
